package model.map;

public class Direction
{
	// need to revisit to fix x,y numbers
	public static final Direction N = new Direction(-1, -1, "N");
	public static final Direction NE = new Direction(0, -1, "NE");
	public static final Direction SE = new Direction(1, 0, "SE");
	public static final Direction S = new Direction(1, 1, "S");
	public static final Direction SW = new Direction(0, 1, "SW");
	public static final Direction NW = new Direction(-1, 0, "NW");
	public static final Direction C = new Direction(0, 0, "C");
	
	private static final Direction[] hexDirections = {N, NE, SE, S, SW, NW};
	
	private int x, y;
	private String directionName;
	
	private Direction(int x, int y, String name)
	{
		this.x = x;
		this.y = y;
		this.directionName = name;
	}
	
	private int index()
	{
		for (int i = 0; i < hexDirections.length; i++)
			if (hexDirections[i] == this)
				return i;
		return -1;
	}
	
	public Direction getOpposite()
	{
		if (this == Direction.C)
			return this;
		return hexDirections[(index() + 3) % 6];
	}
	
	public Direction getClockwise()
	{
		if (this == Direction.C)
			return this;
		return hexDirections[(index() + 1) % 6];
	}
	
	public Direction getCounterClockwise()
	{
		if (this == Direction.C)
			return this;
		return hexDirections[(index() + 5) % 6];
	}
	
	public Direction getOppClockwise()
	{
		if (this == Direction.C)
			return this;
		return getOpposite().getClockwise();
	}
	
	public Direction getOppCounterClockwise()
	{
		if (this == Direction.C)
			return this;
		return getOpposite().getCounterClockwise();
	}
	
	public String direction()
	{
		return directionName;
	}
	
	public String toString()
	{
		return direction();
	}
	
	public int getX()
	{
		return x;
	}
	
	public int getY()
	{
		return y;
	}
}
